<template>
	<view class="container">
		<view @click="gochange('avatur')" class="ava">
			<Cell title="头像"></Cell>
			<image class="avatur" :src="peopleinfo.avatur"></image>
		</view>
		<view @click="gochange('name')"><Cell title="姓名" :content="peopleinfo.name"></Cell></view>
		<view @click="gochange('gender')"><Cell title="性别" :content="peopleinfo.gender===0?'女':'男'"></Cell></view>
		<view @click="gochange('address')"><Cell title="服务地区" :content="peopleinfo.address"></Cell></view>
		<view @click="gochange('service')"><Cell title="服务类型" content=""></Cell></view>
		<view @click="gochange('introduction')"><Cell title="个人介绍" :content="peopleinfo.introduction"></Cell></view>
		<view @click="gochange('experience')"><Cell title="带宠经历" :content="peopleinfo.experience"></Cell></view>
		<view @click="gochange('zhuyi')"><Cell title="注意事项" :content="peopleinfo.zhuyi"></Cell></view>
	</view>
</template>

<script lang="ts" setup>
	import {ref,reactive} from "vue"
	import {onShow} from "@dcloudio/uni-app"
	import Cell from "../components/cell.vue"
	import http from "@/utils/request.js"
	onShow(()=>{
		let obj=uni.getStorageSync('peopleinfo')
		if(obj)peopleinfo.value=obj;
	})
	
	let peopleinfo=ref({})
	
	function gochange(str){
		switch(str){
			case 'name':
				uni.navigateTo({
					url:"/pages/user/edit/nickname"
				});
				break;
			case 'gender':
				uni.navigateTo({
					url:"/pages/user/edit/gender"
				});
				break;
			case 'address':
				uni.navigateTo({
					url:"/pages/user/edit/location"
				});
				break;
			case 'service':
				uni.navigateTo({
					url:"/pages/user/edit/service"
				});
				break;
			case 'introduction':
				uni.navigateTo({
					url:"/pages/user/edit/information"
				});
				break;
			case 'experience':
				uni.navigateTo({
					url:"/pages/user/edit/experience"
				});
				break;
			case 'zhuyi':
				uni.navigateTo({
					url:"/pages/user/edit/zhuyi"
				});
				break;
			case 'avatur':
				changeavatur()
		}
	}
	function changeavatur(){
		uni.chooseImage({
			count:1,
			success(res){
				uploads(res.tempFilePaths[0])
			},
			fail(err){
				console.log(err)
			}
		})
	}
	function uploads(e){
		uni.uploadFile({
			url:'http://localhost:82/api/images/upload',
			filePath:e,
			name:'file',
			header: { "Content-Type": "multipart/form-data" },
			formData:{
				'user':peopleinfo.value.people_id,
				'use':'avatur',
				'time':Date.now()
			},
			success(res){
				peopleinfo.value.avatur=JSON.parse(res.data).imgUrl
				let response=http.post('/people/updatepeople',{peopleinfo:peopleinfo.value})
				response.then(res=>{
					if(res.data.code===200){
						uni.setStorageSync('peopleinfo',peopleinfo.value)
					}
				})
			}
		})
	}
</script>

<style lang="scss">
.container{
	width: 100%;
	
	.ava{
		width: 100%;
		position: relative;
		
		.avatur{
			width: 100rpx;
			height: 100rpx;
			border-radius: 25rpx;
			position: absolute;
			right: 60rpx;
			top:50%;
			transform: translateY(-50%);
		}
	}
}
</style>
